namespace ODT.Intellisense.Models
{
	public class InputModel
	{
		private int caretIndex;

		private string content = string.Empty;

		public string Content
		{
			get
			{
				return content;
			}
			set
			{
				SetContent(value);
			}
		}

		public int CaretIndex
		{
			get
			{
				return caretIndex;
			}
			set
			{
				if (value < 0)
				{
					caretIndex = 0;
				}
				else if (value > Content.Length)
				{
					caretIndex = Content.Length;
				}
				else
				{
					caretIndex = value;
				}
			}
		}

		public string BeforeCaret
		{
			get
			{
				if (string.IsNullOrEmpty(Content))
				{
					return string.Empty;
				}
				return Content.Substring(0, CaretIndex);
			}
		}

		public string AfterCaret
		{
			get
			{
				if (string.IsNullOrEmpty(Content))
				{
					return string.Empty;
				}
				if (CaretIndex >= Content.Length)
				{
					return string.Empty;
				}
				return Content.Substring(CaretIndex, Content.Length - CaretIndex);
			}
		}

		protected virtual void SetContent(string value)
		{
			content = value;
		}
	}
}
